﻿using DSGL_WebAPI.Modes;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace DSGL_WebAPI.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        // GET:查询用户集合
        [HttpGet]
        //[Route("[action]")]
        public List<User> Get()
        {
            //创建用户集合
            List<User> user = new List<User>();
            user.Add(new Modes.User{ UserId = "1", UserName = "张三" });
            user.Add(new Modes.User{ UserId = "2", UserName = "李四" });
            return user;
        }

        //// GET 根据id查询用户
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // POST 添加用户
        [HttpPost]
        public void AddUser ([FromBody]User user)
        {
            Console.WriteLine($"添加用户Id：{user.UserId}");
            Console.WriteLine($"添加用户name：{user.UserName}");
            Console.WriteLine("添加用户成功");
        }

        // PUT 修改用户
        [HttpPut("{id}")]
        public void UpdatesUser(int id, [FromBody]User user)
        {
            Console.WriteLine($"修改用户Id：{user.UserId}");
            Console.WriteLine($"修改用户name：{user.UserName}");
            Console.WriteLine("修改用户成功");
        }

        // DELETE 删除用户
        [HttpDelete("{id}")]
        public void DeleteUser(int id)
        {
            Console.WriteLine($"删除用户，根据Id：{id}");
            Console.WriteLine($"删除成功");
        }
    }
}
